package com.cat.dataStructure03;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/find-missing-observations/description/
 * @create 2025/11/3 17:49
 * @since JDK17
 */

public class Solution08 {
    public int[] missingRolls(int[] rolls, int mean, int n) {
        int[] ans = new int[n];
        int m = rolls.length, sum = mean * (m + n); // 原本的总和
        for (int x : rolls) {
            sum -= x;
        }
        // sum : 长度为n的数组的值的总和，且ans[i] : [1, 6]
        if (sum < n || (sum + 5) / 6 > n) { // 放不了
            return new int[0];
        }
        int ave = sum / n, t = sum % n;
        for (int i = 0; i < n; i++) {
            ans[i] = ave + (i < t ? 1 : 0);
        }

        return ans;
    }
}
